#include <cmath>
#include <iostream>
#include <map>
using namespace std;

int main() {
    int n1, n2;
    cin >> n1;
    map<int, double> m1, m2; // m1存储被除数（包括最后的余数），m2存储商
    int a[100000];           //存储除数的指数
    double b[100000]; //存储除数的系数
    int e, max1 = 0, max2 = 0;
    double c;
    for (int i = 0; i < n1; i++) {
        cin >> e >> c;
        m1[e] = c;
        if (i == 0)
            max1 = e;
    }
    cin >> n2;
    for (int i = 0; i < n2; i++) {
        cin >> a[i];    //除数的指数
        cin >> b[a[i]]; //除数的系数
        if (i == 0)
            max2 = a[i];
    }
    int i = max1;
    while (i >= max2) {
        int diff = i - a[0];
        m2[diff] = m1[i] / b[a[0]];
        for (int j = 0; j < n2; j++) {
            m1[diff + a[j]] -= m2[diff] * b[a[j]];
        }
        i--;
    }
    int cnt1 = 0, cnt2 = 0;
    for (auto it = m1.begin(); it != m1.end(); it++) {
        if (abs(it->second) < 0.05)
            it->second = 0;
        else
            cnt1++;
    }
    for (auto it = m2.begin(); it != m2.end(); it++) {
        if (abs(it->second) < 0.05)
            it->second = 0;
        else
            cnt2++;
    }
    if (cnt2 == 0)
        cout << "0 0 0.0";
    else {
        cout << cnt2;
        for (i = max1; i >= 0; i--) {
            if (m2[i])
                printf(" %d %.1lf", i, m2[i]);
        }
    }
    cout << endl;
    if (cnt1 == 0)
        cout << "0 0 0.0";
    else {
        cout << cnt1;
        for (i = max1; i >= 0; i--) {
            if (m1[i])
                printf(" %d %.1lf", i, m1[i]);
        }
    }
    return 0;
}
